package com.summer.tools.flowable.service.impl;

import com.summer.tools.common.utils.BeanUtil;
import com.summer.tools.flowable.VO.FormModel;
import com.summer.tools.flowable.common.IdGenerator;
import com.summer.tools.flowable.orm.model.ProcessFormField;
import com.summer.tools.flowable.orm.dao.ProcessFormFieldMapper;
import com.summer.tools.flowable.service.IProcessFormFieldService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 表单字段表 服务实现类
 * </p>
 *
 * @author john.wang
 * @since 2021-08-19
 */
@Service
public class ProcessFormFieldServiceImpl extends ServiceImpl<ProcessFormFieldMapper, ProcessFormField> implements IProcessFormFieldService {

    @Override
    public void saveBatch(FormModel form, String formId) {

        List<ProcessFormField> fields = new ArrayList<>(10);
        form.getFields().forEach(f -> {
            ProcessFormField field = new ProcessFormField();
            BeanUtil.copyProperties(f, field, null);
            field.setId(IdGenerator.generateId()).setKey(f.getId()).setFormId(formId);
            fields.add(field);
        });
        this.saveBatch(fields);
    }
}
